package models

import (
	"git.oschina.net/YPTArch/appcenter/sys/db"
	"database/sql"
	"fmt"
)

var ApplicationService *Application = new(Application)

//application struct define
type Application struct {
	AppId   string //AppId	36
	AppName string //应用名称	50
	AppDesc string //应用描述	500
	BaseModel
}
func (*Application) Create(app *Application)(bool, error) {
	err:=dbrepository.MySqlDB.Exec("INSERT INTO `Application` (`AppId`,`AppName`,`AppDesc`) VALUES (?,?,?);",app.AppId,app.AppName,app.AppDesc)
	if err!=nil{
		return false,err
	}
	return true,nil
}

func (*Application)GetByAppId(appId string) (*Application,error) {
	fmt.Println(appId)

	app := new(Application)
	rowHandle := func(isHasRows bool, row *sql.Rows) error {
		if !isHasRows {
			app = nil
			return nil
		}
		err := row.Scan(&app.AppId,&app.AppName, &app.AppDesc,&app.IsDel)
		fmt.Println(err)
		return err
	}
	err:= dbrepository.MySqlDB.QueryRow("SELECT `AppId`,`AppName`,`AppDesc`,`IsDel` FROM `Application` where AppId=?",rowHandle,appId)
	fmt.Println(app)
	if err != nil {
		fmt.Println(err)
		return nil, err
	}
	return app, nil
	
}



